package com.cy.mall.web.front.wj;

import com.cy.mall.model.Result;
import com.cy.mall.model.ao.wj.WsOrderAddAO;
import com.cy.mall.model.ao.wj.WsOrderEditAO;
import com.cy.mall.model.domain.wj.WsOrder;
import com.cy.mall.service.wj.WsOrderService;
import com.cy.mall.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description 前台-万税贷询单管理
 * @Author tanyilin
 * @Date 2019/6/6 14:48
 */
@RestController
@RequestMapping("/customer/ws/order")
@Api(tags = "前台-万税贷询单管理")
public class WsOrderController extends BaseController {

    @Autowired
    private WsOrderService wsOrderService;

    @ApiOperation("新增订单")
    @PostMapping("/do/add")
    public Result doAddWsOrder(@Validated WsOrderAddAO addAO, BindingResult bindingResult) {

        this.checkError(bindingResult);
        Result result = wsOrderService.addWsOrder(addAO, this.getLoginCustomer().getCustomerId());
        if(!result.isOk()) {
            return fail("新增万税贷询单失败");
        }
        return result;
    }

    @ApiOperation("保存编辑订单")
    @PostMapping("/do/edit")
    public Result doEditWsOrder(@Validated WsOrderEditAO editAO, BindingResult bindingResult) {

        this.checkError(bindingResult);
        WsOrder updateWsOrder = new WsOrder();
        BeanUtils.copyProperties(editAO, updateWsOrder);
        updateWsOrder.setId(editAO.getWsOrderId());
        wsOrderService.editWsOrder(updateWsOrder);

        return ok();
    }

}
